<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>个人中心 - 工作量计算系统</title>
    <meta HTTP-EQUIV="pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Cache-Control" CONTENT="no-store, must-revalidate">
    <meta HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta HTTP-EQUIV="expires" CONTENT="0">


    <link rel="Shortcut Icon" href="../images/favicon.ico"/>
    <link rel="stylesheet" href="../css/zone.css">
    <link rel="stylesheet" href="../src/css/layui.css">
    <script src="../src/layui.js"></script>
    <script src="../js/jquery-3.2.1.js"></script>


    <!--必须放最后-->
    <script src="../js/setting.js"></script>


</head>
<body>

<ul class="layui-nav" lay-filter='demo'>
    <li class="layui-nav-item ">
        <a href="myzone.html">
            <i class="layui-icon">
                &#xe603;
            </i>
            个人中心
        </a>
    </li>
    <li style="float: right" class="layui-nav-item "><a href="/logout">退出</a></li>
</ul>

<main>
    <div class="layui-form layui-form-pane" action="">

        <div class="layui-inline" style="align-items: center;">
            <div class="layui-inline">

                <div class="layui-input-inline">
                    <label class="layui-form-label">学期</label>
                    <div class="layui-input-inline">
                        <select name="interest" lay-filter="aihao">
                            <option value=""></option>
                            <option value="0">2016</option>
                            <option value="1" selected="">2017</option>
                            <option value="2">2018</option>
                            <option value="3">2019</option>
                        </select>
                    </div>
                </div>

                <div class="layui-input-inline">
                    <label class="layui-form-label">类别：</label>
                    <div class="layui-input-inline">
                        <select name="modules" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            <!--落地-->
                            <optgroup label="落地">
                                <option value="1">课堂教学</option>
                                <option value="2">实验</option>
                                <option value="3">课程设计</option>
                                <option value="4">毕业设计</option>
                                <option value="5">教学实习</option>
                                <option value="6">毕业实习</option>
                                <option value="7">网络课程</option>
                                <option value="8">双创项目</option>
                                <option value="9">竞赛</option>
                            </optgroup>
                            <!--异地-->
                            <optgroup label="异地">
                                <option value="1">课堂教学</option>
                                <option value="2">实验</option>
                                <option value="3">课程设计</option>
                                <option value="4">毕业设计</option>
                                <option value="14">无课补贴</option>
                            </optgroup>
                            <!--公共-->
                            <optgroup label="公共">
                                <option value="15">实验教学</option>
                            </optgroup>

                        </select>
                    </div>
                </div>
            </div>
        </div>

        <button class="layui-btn layui-btn-normal">搜索</button>
    </div>

</main>


<script>
    $("#centerid").on('click', function () {
        hideAll()
        $("#center").fadeIn();
    });
    $("#passwordid,#url2psw").on('click', function () {
        hideAll()
        $("#password").fadeIn();
    });
    $("#alertid").on('click', function () {
        hideAll()
        $("#alert").fadeIn();
    });


    $("#up").on('click', function () {
        var old = $("#old").val();
        var newpsw = $("#new").val();
        var sure = $("#sure").val();
        if (null == old || null == newpsw || null == sure) {
            layer.msg('请输入密码。');
            return;
        } else if (old == newpsw) {
            layer.msg("新密码与旧密码相同。");
            return;
        } else if (newpsw != sure) {
            layer.msg("两次输入新密码不同。");
            return;
        } else if (newpsw.length < 6) {
            layer.msg("新密码长度小于6位。");
            return;
        } else {
            //本地校验通过

        }
        old = strEnc(old, 'amoxu', 'amoxu', 'amoxu');
        newpsw = strEnc(newpsw, 'amoxu', 'amoxu', 'amoxu');
        var newTable = {
            "old": old,
            "newpsw": newpsw
        };
        $.ajax({
            type: 'post'
            , url: "/zone/password"
            , data: newTable
            , dataType: 'json'
            , contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
            , success: function (res) {
                if (res["status"] == 1) {
                    layer.msg(res['msg']);
                    return false;
                } else {
                    layer.msg("修改成功，请重新登录，以确认密码。");
                    setTimeout("self.location = \"/auth/author.html\";", 2000);
                }
            }
            , error: function (res) {
                layer.alert("错误码：" + res.status+"<br>"+res.statusText);
            }
        });


    });
    $("#uup").on('click', function () {
        var uname = $("#uname").val();
        var umail = $("#umail").val();
        var uquestion = $("#uquestion").val();
        var uanswer = $("#uanswer").val();

        if (uname == old || null == uquestion || null == umail || null == uanswer) {
            layer.msg('必填栏目不允许为空。');
            return;
        } else {
            //本地校验通过
        }

        var newTable = {
            "name": uname,
            "mail": umail,
            "question": uquestion,
            "answer": uanswer
        };

        $.ajax({
            type: 'post'
            , url: "/zone/update"
            , data: newTable
            , dataType: 'json'
            , contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
            , success: function (res) {
                if (res["status"] == 1) {
                    layer.msg(res['msg']);
                    return false;
                } else {
                    layer.msg("修改成功。");
                }
            }
            , error: function (res) {
                layer.alert("错误码：" + res.status+"<br>"+res.statusText);
            }
        });


    });


    function hideAll() {
        $("#center").hide();
        $("#password").hide();
        $("#alert").hide();
    }

    if (window.location.hash == "#password") {
        hideAll()
        $("#password").fadeIn();
    } else if (window.location.hash == "#alert") {
        hideAll()
        $("#alert").fadeIn();
    } else {

    }
    layui.use(['layer'], function () {
        var index = layer.msg("加载中", {icon: 16, shade: 0.01});
        $.ajax({
            type: 'get'
            , url: "/zone/getDetail"
            , dataType: 'json'
            , contentType: 'application/x-www-form-urlencoded;charset=UTF-8'
            , success: function (res) {
                if (res["status"] == 1) {
                    layer.msg(res['msg']);
                    return false;
                } else {
                    //加载成功

                    //{"count":0,// "data":[// {"answer":"*",// "colleage":"信息工程",// "id":10000,// "level":1,// "mail":"123",// "password":"********************************",// "question":"12",// "teacherId":1001,// "user":"zs"}],"msg":"","status":0}


                    var user = res['data'][0]['user'];
                    var mail = res['data'][0]['mail'];
                    var question = res['data'][0]['question'];
                    var colleages = res['data'][0]['colleage'];
                    var answers = res['data'][0]['answer'];
                    var tid = res['data'][0]['tid'];
                    $("#name").html(user);
                    $("#uname").val(user);
                    $("#mail").html(mail);
                    $("#umail").val(mail);
                    $("#question").html(question);
                    $("#uquestion").val(question);
                    $("#college").html(colleages);
                    $("#ucollege").val(colleages);
                    $("#answer").html(answers);
                    $("#uanswer").val();
                    $("#tid").html(tid);
                    $("#uid").val(tid);
                    layer.close(layer.index);
                    return;

                }
            }
            , error: function (res) {
                layer.alert("错误码：" + res.status+"<br>"+res.statusText);
            }
        });

    });
    layui.use(['form'], function () {
        var form = layui.form
    });
</script>


</body>
</html>